Skip to content

Conversation

@wenyihu6
Copy link
Contributor

@wenyihu6 wenyihu6 commented Nov 20, 2025

TODO:

  • Putting this up for discussion - I still need to understand the code here better to see whether this fix is right.
  • More tests are needed as well.
  • We’re also reusing the same rac.buf.replicaConstraintIndices
    if spanConfig.constraints != nil {
    rac.constraints.constraints = spanConfig.constraints
    analyzeFunc(&rac.constraints, false /* isVoterConstraints */)
    }
    if spanConfig.voterConstraints != nil {
    rac.voterConstraints.constraints = spanConfig.voterConstraints
    analyzeFunc(&rac.voterConstraints, true /* isVoterConstraints */)
    }
    across two calls. Sometimes we clear the slice in the loop, but I’m not sure whether they always get cleared before the second call and whether that can cause contamination and this scratch space is reused between two calls.

Previously, we were incorrectly including both voterIndex and nonVoterIndex in satisfiedByReplica for voter constraints's doneFunc, which didn’t seem right. I was initially surprised that nonVoterIndex showed up at all for satisfiedByReplica of voter constraints. It might be accounting for cases where a promotion or demotion might be needed. So satisfiedByReplica[nonVoterIndex] for a voter constraint may legitimately be non-zero.

Previously, we were incorrectly including both voterIndex and nonVoterIndex in satisfiedByReplica for voter constraints's doneFunc, which didn’t seem right. I was initially surprised that nonVoterIndex showed up at all for satisfiedByReplica of voter constraints. It might be accounting for cases where a promotion or demotion might be needed. So satisfiedByReplica[nonVoterIndex] for a voter constraint may legitimately be non-zero.

TODO:
Putting this up for visibility and discussion — I still need to understand the code here better to see whether this fix is right; something feels off. More tests are needed as well.
@blathers-crl
Copy link

blathers-crl bot commented Nov 20, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@wenyihu6 wenyihu6 requested review from sumeerbhola and tbg November 20, 2025 04:51
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @tbg)


pkg/kv/kvserver/allocator/mmaprototype/constraint.go line 885 at r1 (raw file):

				if isVoterConstraints {
					// For voter constraints, only voters can satisfy them.
					return len(ac.satisfiedByReplica[voterIndex][j]) >= int(ac.constraints[j].numReplicas)

I think this is a step in the right direction.
We do want to not be done with a voter constraint if we are still iterating over voters (kind==voterIndex), until it is satisfied purely by voters.
But if we now on kind=nonVoterIndex we don't necessarily want to stuff them all into a single constraint that is not fully satisfied by voters. That is, we should move on once it is satisfied by voters + non-voters, giving us the change to distribute the non-voters over other constraints. This will allow for distributing the non-voters across more constraints that need satisfying.

btw, we should add test cases to TestRangeAnalyzedConstraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants